﻿<Window x:Class="MissedMemo.MeatAndCheeseDisc.OrderEntry.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:data="clr-namespace:MissedMemo.MeatAndCheeseDisc.BusinessLogic;assembly=BusinessObjects"
    xmlns:local="clr-namespace:MissedMemo.MeatAndCheeseDisc.OrderEntry"
    Title="MeatAndCheeseDisc Management System 2008"
    Height="500" Width="400">

    <Window.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="resOrderTemplates.xaml" />
            </ResourceDictionary.MergedDictionaries>
            
            <local:IndexToEnabledStateConverter x:Key="IndexToEnabledStateConverter" />

            <!-- Technique to hide ListBoxItem SELECTION border -->
            <Style TargetType="ListBoxItem">
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                </Style.Resources>
            </Style>

            <Style x:Key="ButtonPanelStyle" TargetType="DockPanel" >
                <Style.Resources>
                    <Style TargetType="Button">
                        <Setter Property="DockPanel.Dock" Value="Right" />
                        <Setter Property="Width" Value="65" />
                        <Setter Property="Height" Value="23" />
                    </Style>
                </Style.Resources>
                <Setter Property="LastChildFill" Value="false" />
            </Style>

        </ResourceDictionary>
    </Window.Resources>

    
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Save" Executed="OnRequestSaveEditChanges" />
    </Window.CommandBindings>
    
    
    <Grid Name="layoutRoot" >

        <Grid Margin="10" DataContext="{x:Static local:App.OrderCollection}" >

            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <ListBox Name="listOrders" Padding="2,3" Grid.Row="0"
                 ItemsSource="{Binding}" Margin="0,0,0,10"
                 HorizontalContentAlignment="Stretch"
                 ItemTemplate="{StaticResource OrderTemplate}" />

            <DockPanel Grid.Row="1" Style="{StaticResource ButtonPanelStyle}" >
                <Button Content="Delete" Click="OnDeleteOrder"
                        IsEnabled="{Binding SelectedIndex, ElementName=listOrders, Converter={StaticResource IndexToEnabledStateConverter}}" />
                <Button Margin="3,0" Content="Add" Click="OnAddOrder" />
                <Button Margin="24,0" Content="Edit" Click="OnEditOrder"
                        IsEnabled="{Binding SelectedIndex, ElementName=listOrders, Converter={StaticResource IndexToEnabledStateConverter}}" />
            </DockPanel>

        </Grid>
        
        <!-- EditPanel floats OVER TOP OF underlying list, buttons, etc. -->
        <local:viewOrderEditPanel x:Name="OrderEditPanel" Height="0" Width="auto" />
    
    </Grid>
    
</Window>
